<?php

namespace App\Controller\Test;


use App\Controller\AbstractController;
use App\Dao\Users\UsersDao;
use App\Model\Admin\Menu;
use App\Model\Domain;
use App\Model\Users\UsersAccount;
use App\Service\Statics\HomeStaticsService;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Guzzle\ClientFactory;
use Statickidz\GoogleTranslate;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\GetApi;
use Yj\Apidog\Annotation\PostApi;

/**
 * @ApiController(prefix="test")
 */
class testController extends AbstractController
{
    /**
     * @Inject()
     * @var ClientFactory
     */
    protected $clientFactory;

    /**
     * @Inject()
     * @var Menu
     */
    protected $menu;

    /**
     * @Inject()
     * @var ClientFactory
     */
    protected $http;


    /**
     * @GetApi(path="tr")
     */
    public function tr()
    {
        _HTTP();

        $http = $this->http->create();
//        while(1){
        $trs = Db::table('tr01')
            ->whereNull('en_text')
            ->first();
        $id = $trs->id;
        $text = $trs->ori_text;
        $en_text = GoogleTranslate::translate('tr', 'en', $text);
        Db::table('tr01')->where('id', $id)->update([
            'en_text' => $en_text
        ]);
//            sleep(1);
//        }
        _GetLastSql();
    }

    /**
     * @Inject()
     * @var HomeStaticsService
     */
    protected $homeStaticsService;

    /**
     * @GetApi(path="test1")
     */
    public function test()
    {
        dump('test');


//        $this->menu->where('id', 1)->first();
//        _GetLastSql(1);
//        dump(22);
//        dump($params = $this->getValidatorData());
//
//        _SUCCESS(11);
//        $path = 'exp004.xlsx';
//        $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
//        $objPHPExcel = $reader->load(config('file.storage.local.root') . '/' . $path);
//        $sheet = $objPHPExcel->getSheet(0);   //excel中的第一张sheet
//        $highestRow = $sheet->getHighestRow();       // 取得总行数
//        $client = $this->clientFactory->create(['verify' => false]);
//        for ($j = 2; $j <= $highestRow; $j++) {
//            $url = $objPHPExcel->getActiveSheet()->getCell("A" . $j)->getValue();
//            Db::table('domain')->insert(['domain' => $url]);
//        }
    }



}